#include "texturelibrary.h"

// Extern variables declared in headers need to have
// variable definitions in a .cpp file.
std::map<std::string, sf::Texture*> TT::TextureLibrary;


void TT::FreeTexture(const std::string &s)
{
	// find the texture s in our library and delete it:
	delete TT::TextureLibrary[s];
	// Remove that entry from our library:
	TT::TextureLibrary.erase(s);
}


void TT::LoadTexture(const std::string &s)
{
	using namespace sf;
	using namespace std;

	// Look for the entry already in our dictionary:
	if (TT::TextureLibrary.find(s) != TT::TextureLibrary.end())
	{
		// We found the texture already in the library
		// Return without loading it!
		return;
	}

	// Create a new texture:
	Texture *texture = new Texture;
	// Load in a texture from a file:
	texture->loadFromFile(s);
	// Register this texture with our texture library:
	TT::TextureLibrary[s] = texture;
}
